//
//  HDIntroDetailViewController.m
//  healthyexpert
//
//  Created by Liu Penny on 15/1/27.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDIntroDetailViewController.h"

@interface HDIntroDetailViewController ()

@end

@implementation HDIntroDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    CGSize result = [[UIScreen mainScreen] bounds].size;
    
    if((self.pageIndex < IntroNo) &&(self.pageIndex>0))
    {
        
        NSString *introfilePath = [[NSBundle mainBundle]pathForResource:self.imageFile ofType:@"png"];
        NSData *image = [NSData dataWithContentsOfFile:introfilePath];
        UIImageView *introImageView = [[UIImageView alloc]initWithImage:[UIImage  imageWithData:image]] ;
        [introImageView setFrame:CGRectMake(0,0, result.width, result.height)];
        [self.view addSubview:introImageView];
        introImageView = nil;
        
        if(self.pageIndex == MAX_Intro )
        {
            CGRect btnControlRect= CGRectMake(result.width/2-60, result.height-60, 120, 36);
            UIButton *btnControl=[[UIButton alloc] initWithFrame:btnControlRect];
            UIImage * BGimage = [UIImage imageNamed:@"color@2x.png"];
            CGFloat top = 6;
            CGFloat bottom = 6;
            CGFloat left = 6;
            CGFloat right = 6;
            UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
            BGimage = [BGimage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
            [btnControl setBackgroundImage:BGimage forState:UIControlStateNormal];
            [btnControl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btnControl setTitle:@"立即体验" forState:UIControlStateNormal];
            [btnControl addTarget:self action:@selector(ClickControlAction) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:btnControl];

        }

    }

}

- (void)ClickControlAction{
    
    HDAppDelegate *app = (HDAppDelegate*)[[UIApplication sharedApplication]delegate];
    
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    
    if([[NSUserDefaults standardUserDefaults]boolForKey:@"login"])
    {
        app.storyBoard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil];
//        [self presentViewController:[app.storyBoard instantiateInitialViewController] animated:NO completion:nil];
        app.window.rootViewController = [app.storyBoard instantiateInitialViewController];
        [app.window makeKeyAndVisible];
    }
    else
    {
     
        
        
        app.storyBoard = [UIStoryboard storyboardWithName:@"LogInOutStoryboard" bundle:nil];
        [self presentViewController:[app.storyBoard instantiateInitialViewController] animated:NO completion:nil];
//        app.window.rootViewController = [app.storyBoard instantiateInitialViewController];
        app.window.rootViewController = [app.storyBoard instantiateInitialViewController];
        [app.window makeKeyAndVisible];
        
           }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
